<?php $layout = 'admin';
$title = '系统设置 - MyCMS'; ?>

<form method="post" action="/admin/settings/update">
    <?php echo App\Core\CSRF::field(); ?>

    <!-- 基本设置 -->
    <div class="card">
        <div class="card-header">
            <h2>基本设置</h2>
        </div>
        <div class="card-body">
            <div style="display: grid; gap: 1.5rem;">
                <div>
                    <label for="site_name" style="display: block; margin-bottom: 0.5rem; font-weight: 500; color: #333;">
                        网站名称
                    </label>
                    <input type="text"
                        id="site_name"
                        name="site_name"
                        value="<?= htmlspecialchars($settings['site_name'] ?? $defaults['site_name']) ?>"
                        style="width: 100%; padding: 0.75rem; border: 1px solid #ddd; border-radius: 4px; font-size: 1rem;"
                        required>
                    <small style="color: #666; font-size: 0.85rem;">显示在网站标题和页面头部的名称</small>
                </div>

                <div>
                    <label for="site_description" style="display: block; margin-bottom: 0.5rem; font-weight: 500; color: #333;">
                        网站描述
                    </label>
                    <textarea id="site_description"
                        name="site_description"
                        rows="3"
                        style="width: 100%; padding: 0.75rem; border: 1px solid #ddd; border-radius: 4px; font-size: 1rem; resize: vertical;"><?= htmlspecialchars($settings['site_description'] ?? $defaults['site_description']) ?></textarea>
                    <small style="color: #666; font-size: 0.85rem;">网站的简短描述，用于SEO和页面介绍</small>
                </div>

                <div>
                    <label for="admin_email" style="display: block; margin-bottom: 0.5rem; font-weight: 500; color: #333;">
                        管理员邮箱
                    </label>
                    <input type="email"
                        id="admin_email"
                        name="admin_email"
                        value="<?= htmlspecialchars($settings['admin_email'] ?? $defaults['admin_email']) ?>"
                        style="width: 100%; padding: 0.75rem; border: 1px solid #ddd; border-radius: 4px; font-size: 1rem;"
                        placeholder="admin@example.com">
                    <small style="color: #666; font-size: 0.85rem;">用于接收系统通知和重要信息</small>
                </div>
            </div>
        </div>
    </div>

    <!-- 内容设置 -->
    <div class="card" style="margin-top: 1.5rem;">
        <div class="card-header">
            <h2>内容设置</h2>
        </div>
        <div class="card-body">
            <div style="display: grid; gap: 1.5rem;">
                <div>
                    <label for="posts_per_page" style="display: block; margin-bottom: 0.5rem; font-weight: 500; color: #333;">
                        每页文章数量
                    </label>
                    <input type="number"
                        id="posts_per_page"
                        name="posts_per_page"
                        value="<?= intval($settings['posts_per_page'] ?? $defaults['posts_per_page']) ?>"
                        min="1"
                        max="50"
                        style="width: 200px; padding: 0.75rem; border: 1px solid #ddd; border-radius: 4px; font-size: 1rem;"
                        required>
                    <small style="color: #666; font-size: 0.85rem;">文章列表页面每页显示的文章数量（1-50）</small>
                </div>

                <div>
                    <label for="timezone" style="display: block; margin-bottom: 0.5rem; font-weight: 500; color: #333;">
                        时区设置
                    </label>
                    <select id="timezone"
                        name="timezone"
                        style="width: 300px; padding: 0.75rem; border: 1px solid #ddd; border-radius: 4px; font-size: 1rem;">
                        <option value="Asia/Shanghai" <?= ($settings['timezone'] ?? $defaults['timezone']) === 'Asia/Shanghai' ? 'selected' : '' ?>>
                            Asia/Shanghai (北京时间)
                        </option>
                        <option value="UTC" <?= ($settings['timezone'] ?? $defaults['timezone']) === 'UTC' ? 'selected' : '' ?>>
                            UTC (协调世界时)
                        </option>
                        <option value="America/New_York" <?= ($settings['timezone'] ?? $defaults['timezone']) === 'America/New_York' ? 'selected' : '' ?>>
                            America/New_York (东部时间)
                        </option>
                        <option value="Europe/London" <?= ($settings['timezone'] ?? $defaults['timezone']) === 'Europe/London' ? 'selected' : '' ?>>
                            Europe/London (伦敦时间)
                        </option>
                    </select>
                    <small style="color: #666; font-size: 0.85rem;">系统显示时间的时区设置</small>
                </div>
            </div>
        </div>
    </div>

    <!-- 功能设置 -->
    <div class="card" style="margin-top: 1.5rem;">
        <div class="card-header">
            <h2>功能设置</h2>
        </div>
        <div class="card-body">
            <div style="display: grid; gap: 1.5rem;">
                <div style="display: flex; align-items: center; padding: 1rem; background: #f8f9fa; border-radius: 4px;">
                    <input type="checkbox"
                        id="allow_registration"
                        name="allow_registration"
                        value="1"
                        <?= ($settings['allow_registration'] ?? $defaults['allow_registration']) ? 'checked' : '' ?>
                        style="margin-right: 1rem; transform: scale(1.2);">
                    <div>
                        <label for="allow_registration" style="font-weight: 500; color: #333; cursor: pointer;">
                            允许用户注册
                        </label>
                        <div style="color: #666; font-size: 0.85rem; margin-top: 0.2rem;">
                            关闭后，新用户将无法通过注册页面创建账户
                        </div>
                    </div>
                </div>

                <div style="display: flex; align-items: center; padding: 1rem; background: #fff3cd; border: 1px solid #ffeaa7; border-radius: 4px;">
                    <input type="checkbox"
                        id="maintenance_mode"
                        name="maintenance_mode"
                        value="1"
                        <?= ($settings['maintenance_mode'] ?? $defaults['maintenance_mode']) ? 'checked' : '' ?>
                        style="margin-right: 1rem; transform: scale(1.2);">
                    <div>
                        <label for="maintenance_mode" style="font-weight: 500; color: #856404; cursor: pointer;">
                            ⚠️ 维护模式
                        </label>
                        <div style="color: #856404; font-size: 0.85rem; margin-top: 0.2rem;">
                            开启后，普通用户将无法访问网站，只有管理员可以正常使用
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- 保存按钮 -->
    <div class="card" style="margin-top: 1.5rem; text-align: center;">
        <div class="card-body">
            <button type="submit" class="btn" style="font-size: 1.1rem; padding: 1rem 2rem;">
                💾 保存设置
            </button>
            <div style="margin-top: 1rem; color: #666; font-size: 0.9rem;">
                设置保存后将立即生效，请谨慎操作
            </div>
        </div>
    </div>
</form>

<style>
    input:focus,
    textarea:focus,
    select:focus {
        outline: none;
        border-color: #007bff;
        box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.25);
    }
</style>